//
//  loginVM.m
//  hnGovernment
//
//  Created by 张辉男 on 17/3/9.
//  Copyright © 2017年 安仔. All rights reserved.
//

#import "loginVM.h"
#import "DDbaseNetWork+Login.h"
#import "DDcacheManager.h"

@implementation loginVM
+ (void)loginWithLoginName:(NSString *)loginName password:(NSString *)password controller:(NSObject *)controller success:(successBlock)success{
    [SVProgressHUD showWithStatus:@""];
    [DDNetWorkManager login:loginName passWord:password controller:controller success:^(id result, DDcacheType cacheType, DDresultType resultType) {        
        [DDHudHelper showHudWithResult:result resultSuccess:^{
            NSString *token = result[@"data"][@"token"];
            [cacheManager cacheUserToken:token];
            [loginVM p_queryUserInfoWithToken:token controller:controller success:success];
        }];
    } failure:^(NSError *error) {
        [SVProgressHUD dismiss];
    }];
}

+ (void)p_queryUserInfoWithToken:(NSString *)token controller:(NSObject *)controller success:(successBlock)success {
    [DDNetWorkManager queryAllUseMsgUseToken:token controller:controller success:^(id result, DDcacheType cacheType, DDresultType resultType) {
        if (success) {
            success(result,cacheType,resultType);
        }
    } faliure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"登录失败"];
    }];
}


@end
